exports.ReceivedGiftTableViewCell = UI.ListViewItem.subclass({
    
    className: "ReceivedGiftTableViewCell",
    
    initialize: function(reuseId,cellModel,pw) {
		//$super(reuseId);
    	this._parentWindow = pw;
    	this._cellView = null;
    	this._indexPath_Row = 0;
        this._cellModel = cellModel;
        this._itemId = null;
    },
    
    _onCreateView: function() {
		this._cellView = new CustomCellView();
		
		var cellBgPath = this.getBaseResourcePath() + "cell-background.png";
		var placeholderPath = this.getBaseResourcePath() + "placeholder.png";
		var giftButtonNormalPath = this.getBaseResourcePath() + "button-normal.png";
		var giftButtonPressedPath = this.getBaseResourcePath() + "button-pressed.png";

        this._cellView.setFrame([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(280),TCUtil.getAdjustedY(90)]);
        
		this._cellView.backgroundView = UIFactory.getView([TCUtil.getAdjustedX(10),TCUtil.getAdjustedY(5),TCUtil.getAdjustedX(275),TCUtil.getAdjustedY(90)], null, null);
		this._cellView.addChild(this._cellView.backgroundView);
		
		this._cellView.cellBg = UIFactory.getImage([TCUtil.getAdjustedX(0), TCUtil.getAdjustedY(0), TCUtil.getAdjustedX(275),TCUtil.getAdjustedY(90)], cellBgPath);
		this._cellView.backgroundView.addChild(this._cellView.cellBg);

		this._cellView.useButton = UIFactory.getGenericButton([TCUtil.getAdjustedX(180), TCUtil.getAdjustedY(50), TCUtil.getAdjustedX(70),TCUtil.getAdjustedY(30)], giftButtonNormalPath, giftButtonPressedPath, Core.Localization.getString("USE"), "000000", TCUtil.getAdjustedFontSize(60), null, null);
		this._cellView.addChild(this._cellView.useButton);		
		
        this._cellView._itemName = UIFactory.getTextArea([TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(10), TCUtil.adjustWidthWithDevice(190), TCUtil.adjustHeightWithDevice(30)], "", TCUtil.getAdjustedFontSize(70), UI.ViewGeometry.Gravity.Left, 'ffcc99');
		this._cellView.addChild(this._cellView._itemName);
		
		this._cellView._itemDescription = UIFactory.getTextArea([TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(30), TCUtil.adjustWidthWithDevice(170), TCUtil.adjustHeightWithDevice(30)], "", TCUtil.getAdjustedFontSize(60), UI.ViewGeometry.Gravity.Left, 'ffcc99');
		this._cellView.addChild(this._cellView._itemDescription);
		
		this._cellView._friendName = UIFactory.getTextArea([TCUtil.getAdjustedX(100), TCUtil.getAdjustedY(50), TCUtil.adjustWidthWithDevice(170), TCUtil.adjustHeightWithDevice(30)], "", TCUtil.getAdjustedFontSize(70), UI.ViewGeometry.Gravity.Left, 'ffcc99');
		this._cellView.addChild(this._cellView._friendName);
		
//		this._cellView._BigButton = UIFactory.getGenericButton([TCUtil.getAdjustedY(10),TCUtil.getAdjustedX(5),TCUtil.getAdjustedY(275),TCUtil.getAdjustedX(90)]);
//		this._cellView._BigButton.setAlpha(0.02);
//		this._cellView.addChild(this._cellView._BigButton);

        return this._cellView;
    },
    _onSetView: function(cellView) 
    {	    	
    	//console.log("zaki::::: CELL MODEL FOR RECEIVED IS "+this._cellModel.itemid);
    	var storeItem = GAGameLoader.getStoreHandler().getStoreObjectForKey(this._cellModel.getItemId());
    	this._itemId = this._cellModel.getItemId();

    	cellView._itemName.setText(storeItem.name);
    	cellView._itemDescription.setText(storeItem.description);
 
		cellView._friendName.setText(Core.Localization.getString("SENT_BY")+this._cellModel.getSenderName());
    	
		if(cellView.icon)
		{
			cellView.removeChild(cellView.icon);
			cellView.icon = null;
		}    	

		var icon = new CustomStoreIcon();
		icon.setFrame([TCUtil.getAdjustedX(39), TCUtil.getAdjustedY(27), TCUtil.getAdjustedX(45), TCUtil.getAdjustedY(45)]);
		icon.load(storeItem);
		cellView.icon = icon;
		cellView.addChild(cellView.icon);


//		cellView._BigButton.onclick = function() 
//        {
//            this.onCellTap(this._cellModel);
//        }.bind(this);
//        
	    cellView.useButton.controller = this;
		cellView.useButton.onclick = function() 
        {
            this.onUseTap(storeItem);
        }.bind(this);
    },
    
    onUseTap: function(storeItem)
    {
    	MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		if(TCUtil.getItemType(storeItem) == kItemType.kItemStore)
		{
			//gift code here
			MMGameVariables.setPurchasedItemId(this._itemId);
			MMGameVariables.setPurchasedItem(this._cellModel);
			MMGameVariables.setActionType(kActionType.kActionUseGift);
			MMGameLayer.getControlLayer().addActionAlertWindow(Core.Localization.getString("BUY_STORE_ALERT"));
		}
			
		else if(TCUtil.getItemType(storeItem) == kItemType.kItemDecoration)
		{
			//gift code here
			MMGameVariables.setPurchasedItemId(this._itemId);
			MMGameVariables.setPurchasedItem(this._cellModel);	
			//console.log("zaki::::::item id is..... "+this._itemId);			
			MMGameVariables.setActionType(kActionType.kActionUseGift);
			MMGameLayer.getControlLayer().addActionAlertWindow(Core.Localization.getString("BUY_DECORATION_ALERT"));
		}
			
		this._parentWindow.removeFromParent();
		this._parentWindow.destroy();
    },
    
	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/gifttableview/";
	},

    destroy: function() 
	{
    	
    },
});

